<?php
use app\modules\cruise\models\Room;
use app\modules\cruise\models\RoomCode;
use kartik\file\FileInput;
use app\modules\cruise\models\Customer;

$this->title = "甲板层分房号";

$code = [];
if($deck){
	foreach($deck as $key=>$val){
		if($val['isroom'] == 1){
			$code[$key] = RoomCode::find()->where(['cruise_id'=>$model->id,'deck'=>$key])->all();
		}
	}
}

//所有房型
$all_room_arr = [];
$all_room = Room::find()->all();
if($all_room){
	foreach($all_room as $aroom){
		$all_room_arr[$aroom->id] = $aroom->name.' '.$aroom->code;
	}
}

//赛选条件分组
//团号
$group_arr = [];
$group = Customer::find()->where(['status'=>1])->groupBy(['group'])->all();
if($group){
   foreach($group as $g){
   	 if($g->group){
   	   $group_arr[$g->group] = $g->group;
   	 }else{
   	   $group_arr['none'] = '未分团号';
   	 } 
   }	
}

//体系
$supply_arr = [];
$supply = Customer::find()->where(['status'=>1])->groupBy(['supply'])->all();
if($supply){
   foreach($supply as $s){
   	  if($s->supply){
   	  	$supply_arr[$s->supply] = $s->supply;
   	  }else{
   	  	$supply_arr['none'] = '未分体系';
   	  }
   	  
   }	
}
//职级
// $rank_arr = [];
// $rank = Customer::find()->where(['status'=>1])->groupBy(['rank'])->all();
// if($rank){
//    foreach($rank as $r){
//    	  if($r->rank){
//    	  	$rank_arr[$r->rank] = $r->rank;
//    	  }else{
//    	  	$rank_arr['none'] = '未分职级';
//    	  }	
//    }	
// }
//房间类别
$room_t_arr = [];
$room_t = Customer::find()->where(['status'=>1])->groupBy(['room_id'])->all();
if($room_t){
   foreach($room_t as $rt){
   	  if($rt->room_id){
   	     $room_t_arr[$rt->room_id] = $all_room_arr[$rt->room_id];
   	   }else{
   	   	 $room_t_arr['none'] = '房间类型为空';
   	   } 
   }	
}

?>

<?= yii\web\View::registerCssFile("/css/magic-check.css",['depends' => 'app\assets\AppAsset']) ?>

<style type="text/css">
	.scroll_a::-webkit-scrollbar{width: 10px;height: 10px;background-color: #F5F5F5;} 
	.all-order::-webkit-scrollbar{width: 10px;height: 10px;background-color: #F5F5F5;}  
    /*定义滚动条轨道 内阴影+圆角*/  
    .scroll_a::-webkit-scrollbar-track{-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);border-radius: 8px; background-color: #F5F5F5;} 
    .all-order::-webkit-scrollbar-track{-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);border-radius: 8px; background-color: #F5F5F5;}  
    /*定义滑块 内阴影+圆角*/  
    .scroll_a::-webkit-scrollbar-thumb{border-radius: 8px; -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.3); background-color: #FBAB0E;}
    .all-order::-webkit-scrollbar-thumb{border-radius: 8px; -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.3); background-color: #FBAB0E;}

    .order-all{
	    padding: 0 10px 10px;
	    margin-bottom: 10px;
	    background: #f5f5f5;
	} 
	.deck-nav li{
		margin-left: 1px !important;
	}
    .nav-tabs > li.active > a, .nav-tabs > li.active > a:hover, .nav-tabs > li.active > a:focus{
		border:1px solid #fff;border-bottom-color:#fff;color:#A664A6;
		background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#0482e3), to(#ffffff));
	}
	.nav-tabs{
		border: 0;
		margin-right: 25px;
		border-radius: 4px;
	}
	.deck-nav > li > a{
		border-radius: 0;
		background: #0482e3;
		border:1px solid #0482e3;
		color: #fff;
		margin-right:0px;
		padding: 8px 11px;
	} 
	
	.order-one{border-bottom: 1px dotted #ddd;margin: 0;padding: 10px 0;}
	.p1{font-size: 14px;color:#000;font-weight:bold; margin:5px;}

	#Pagination {
	    padding:20px 0;
	    display: inline-block;
	}
	.pageBtn a {
	    display: inline-block;
	    border: 1px solid #aaa;
	    padding: 2px 5px;
	    margin : 0 3px;
	    font-size: 13px;
	    background: #ECECEC;
	    color: black;
	    text-decoration: none;
	    -moz-border-radius: 2px;
	    -webkit-border-radius: 3px;
	}
	.pageBtn-selected a {
	    display: inline-block;
	    border: 1px solid #A664A6;
	    padding: 2px 5px;
	    margin : 0 3px;
	    font-size: 13px;
	    background: #A664A6;
	    color: white;
	    text-decoration: none;
	    -moz-border-radius: 2px;
	    -webkit-border-radius: 3px;
	}
	.pageBtn a:hover {
	    background: #A664A6;
	    border: 1px solid #A664A6;
	    color: #fff;
	    cursor: pointer;
	}
	.deck-tip{width:140px;height: auto;position: fixed;top: 10px;left: 10px;opacity: 1;overflow: visible;margin-left:5px;padding-top:80px;}
	.room-content {background: #fff;z-index:1;color:#000;position: relative;-webkit-box-shadow: 0 5px 15px rgba(0, 0, 0, .5);
    box-shadow: 0 5px 15px rgba(0, 0, 0, .5);border-radius: 4px;}
	.room-content img{width:120px;text-align: center;margin-top: 10px;margin-left: 10px;}
	.room-content .rc-p{margin:5px 10px;}
	.room-content .s1{color: red;}
	.room-content .s2{padding: 5px;color: #fff;background: #A664A6;width: 25px;height: 25px;}
	.room-content .s3{color:red;}
	.chose-i{color:#000;display: none;}
	.select-list{margin-bottom: 8px;}
	.people-one{margin-left: 30px}
</style>

<div class="excel row" style="margin-bottom: 5px;border-bottom: 1px solid #ddd;">

		<div  style="display: inline-block;margin-left: 10px;">
			<div style="color:#000;font-size:14px;font-weight: bold;line-height:34px;height: 40px;">
				<i class="iconfont" style="color:#A664A6">&#xe686;</i>
				<span style="margin:0 5px;"><?=$model->name?></span>
				【已使用 / 导入房间 / 总房间：<span class="room_num" style="color: #F0AD4E;"><?=$model->roomCodeUseNum?> </span> 间 / <span style="color: #F0AD4E;"><?=$model->roomCodeNum?> </span> 间 / <?=$model->codeNum?> 间】
				</span>
			
			</div>
			
		</div>
		
		<!-- <div style="display: inline-block;float: right;margin-right: 10px;">
			<a  target="_blank" href="/cruise/room-use/index" class="btn btn-info">查看房间</a>
		</div>

		<div style="display: inline-block;float: right;margin-right: 10px;">
			<a data-toggle="modal" data-target=".code-modal"  href="/cruise/deck/create-code?cruise_id=</?= $model->id?>" class="btn btn-primary">添加房间号</a>
		</div>

		<div class="pull-right" style="margin-right: 15px;display: inline-block;">	
			
	        </?php echo FileInput::widget([
	            'language' => 'zh',
	            'name' => 'excel',
	            'id' => 'file-upload',
	            'pluginOptions' => [
	                'uploadUrl' => "/cruise/deck/import",
	                'uploadExtraData' => [
	                    'cruise_id' => $model->id,
	                    '_csrf' => Yii::$app->getRequest()->getCsrfToken(),
	                ],
	                'showPreview' => false,
	                'showCaption' => false,
	                'showRemove' => false,
	                'showUpload' => false,
	                'uploadAsync'=> true,
	                'maxFileCount' => 1,
	                'browseClass' => 'btn btn-warning',
	                'browseIcon' => '<i class="glyphicon glyphicon-cloud-upload"></i>',
	                'browseLabel' => '上传房间号',
	                'fileTypeSettings' => [],
	            ],
	            'options' => ['accept' => '', 'multiple'=>false],
	            ]);?>
	    </div> -->

</div>

<div style="margin:20px 0;line-height: 40px;">
	<span style="font-weight: bold;">舱房类型：</span>			
	<span style="border:1px solid #000;background:#ffffff;color:#000;padding:2px 4px;">未导入</span>
	<span style="border:1px solid #939395;background:#939395;color:#fff;padding:2px 4px;">已分配</span>
				
	<?php 
	   if($room_type){
	   	  foreach($room_type as $type){ ?>	
	   	  			<span style="padding-left: 10px;"><?=\yii::$app->params['room_type'][$type->type]?></span>
	   	  			<?php foreach($color as $val){ 
	   	  				  	if($type->type == $val->type){ ?>
	   	  				  	<span style="border:1px solid <?=$val->color?>;background:<?=$val->color?>;color:#fff;padding: 2px 4px;"><?=$val->type_code?></span>
	   	  			<?php } }?>
	   	  					
	   	  		
	<?php  }} ?>
		
		
</div>	

<ul class="nav nav-tabs deck-nav" role="tablist">
	<?php if($deck){ 
			$first = 0;
			foreach($deck as $k=>$val){ 
					if($val['isroom'] == 1){ 
					 		$first++; ?>
					 <li role="presentation"  <?=$first == 1?'class="active"':''?>><a href="#deck_<?=$k?>" aria-controls="deck_<?=$k?>" role="tab" data-toggle="tab"><?=$k?> F <i class="fa  fa-check-square chose-i ii_<?=$k?>"></i></a></li>
			<?php  };?>
			<?php }?>
	<?php }?>
    
</ul>
<div class="row" style="margin-top:3px;border-top:1px solid #ddd;">
 	<div class="deck-left col-md-6">	
		<div class="tab-content">

		<?php if($deck){ 
			$m_first = 0;
			foreach($deck as $k2=>$val2){ 
				if($val2['isroom'] == 1){ 
					$m_first++; $width = $val2['width']+20; ?>

					<div role="tabpanel" class="tab-pane <?=$m_first == 1?'active':''?>" id="deck_<?=$k2?>" data-i="<?=$k2?>" >
						<div class="scroll_a" style="margin-top: 20px;text-align:center;height:1000px; overflow:auto;"> 
						<svg width="<?=$val2['width']?>" height="<?=$val2['height']?>" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
					 	<defs>
				              <linearGradient id="nt_<?=$k2?>" x1="0%" y1="0%" x2="0%" y2="100%">
							      <stop offset="0%" style="stop-color:rgb(81,82,84); stop-opacity:.4"/>
							      <stop offset="100%" style="stop-color:rgb(81,82,84); stop-opacity:1"/>
							    </linearGradient>
						</defs>
						<image x="0" y="0" width="<?=$val2['width']?>" height="<?=$val2['height']?>" xlink:href="<?=$val2['path']?>"  />

						<?php foreach($code[$k2] as $dval){ 		    
					    	//是否在导入的房间号
					    	$exit_p = in_array($dval->code,$import_code);
					    	//是否已经使用 
					    	$exit = in_array($dval->code,$exit_code);
						?>
						<path id="path_<?=$dval->code?>" class="deck deck-onclick" data-poload="/cruise/deck/room-code?rc_id=<?=$dval->id?>&cruise_id=<?=$model->id?>"  data-id="<?=$dval->id?>" data-deck="<?=$k2?>" data-room-num="<?=($dval->num)?$dval->num:0?>"  data-room-type="<?=$dval->type?>"  data-room="<?=$dval->code?>" data-type-code="<?=$dval->type_code?>"  data-disabled="<?=$exit ? 1 : 0;?>" d="<?=$dval->location?>"
						data-exit = "<?=$exit_p ? 1 : 0 ?>" 
						data-color = "<?=$dval->color?>"
						fill="<?=$exit_p?($exit ? "url(#nt_$k2)" : $dval->color ):'#ffffff'?>"    style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0); opacity:<?=$exit_p?0.7:0?>; cursor: <?=$exit_p ? ($exit?'not-allowed':'pointer'):'not-allowed';?>"  />
						 </path>   
									    	 
						<?php }?>

						</svg>
						</div>	

					</div>

				<?php };?>
				<?php }?>
		<?php }?>
	 	</div>
 	</div>


 	<div class="deck-right col-md-6" style="margin-top:10px;">

		<div class="order-all">	
	 		<div class="order-header" style="padding: 8px 0;margin-bottom: 5px;font-size: 16px;background: #f5f5f5;font-weight: bold;">
	 			查房间
	 		</div>
	 		<div class="order-select" style="padding: 8px;background-color: #ffffff;border-bottom: 1px solid #ddd;">
	 			<div class="select-list">
	 				分房状态：
	 				<div class="radio-inline">
					   <label>
					      <input type="radio" name="room-status" value="0" checked="checked">
					         全部
					   </label>
					</div>
		 			<div class="radio-inline">
					   <label><input type="radio" name="room-status" value="1"> 未分房号
					   </label>
					</div>
					<div class="radio-inline">
					   <label><input type="radio" name="room-status" value="2">
					         已分房号
					   </label>
					</div>
				</div> 

				<div class="select-list">
					姓名：
					<div  style="display: inline-block;">
						<input type="text" name="name-t" id="name-t" class="form-control" placeholder="姓名" value="">
					</div>	
				</div>

				<div class="select-list">
					房间类别：
					<div  style="display: inline-block;">
					<select id="room-t"  class="form-control">
						<option value="0" selected="selected">选择所有房间</option>
						<?php foreach($room_t_arr as $kta=>$vta){ ?>
						<option value="<?=$kta?>"><?=$vta?></option>
						<?php }?>
					</select>
					</div>	
				</div>

				<div class="select-list">
					团号：
					<div  style="display: inline-block;">
					<select id="group" class="form-control">
						<option value="0" selected="selected">选择所有团号</option>
						<?php foreach($group_arr as $kr=>$vr){ ?>
						<option value="<?=$kr?>"><?=$vr?></option>
						<?php }?>
					</select>
					</div>	
				</div>	
				
				<div class="select-list">
					体系：
					<div  style="display: inline-block;">
					<select id="supply" class="form-control">
						<option value="0" selected="selected">选择所有体系</option>
						<?php foreach($supply_arr as $ks=>$vs){ ?>
						<option value="<?=$ks?>"><?=$vs?></option>
						<?php }?>
					</select>
					</div>	
				</div>	
				
	 			
				<div class="row" style="margin: 0;padding-left: 10px;">
					<div class="pull-right">
	 				<button class="btn btn-warning" id="select-order">查询</button>
	 				</div>
	 			</div>
	 		</div>

	 		
 			<div class="order-list" style="padding: 5px;background-color: #ffffff;">
 				<div id="loadgif" style="text-align: center;">
　　				<img  alt="加载中..." src="/img/loading.gif"/>
				</div>
				<div class="all-order" style="max-height:800px; overflow:auto;">

				</div>
				<div class="dw"> 
					<div id="Pagination"><!--这里添加分页按钮栏--></div>
				</div>	
 			</div>
 		</div>	
 	</div>	
</div>

   

<input type="hidden" id="cruise_id" value="<?=$model->id?>">
<input type="hidden" id="select-room" value="0">
<input type="hidden" id="select-room-num" value="0">

<div class="modal fade deck-modal"   id="deckModal" role="dialog" aria-labelledby="myLargeModalLabel">
  <div class="modal-dialog " role="document" style="width:540px;">
      <div class="modal-content">
	 	<!-- 嵌入内容 --> 
	  </div>
  </div>
</div>

<div class="modal fade code-modal" id="code-modal" role="dialog" aria-labelledby="myLargeModalLabel">
  <div class="modal-dialog " role="document" style="width:600px;">
      <div class="modal-content">
	 		<!-- 嵌入内容 --> 
	  </div>
  </div>
</div>

<div class="deck-tip">
    <div class="room-content">
      	   
    </div>	
</div>   

<?= yii\web\View::registerJsFile("/js/layer/layer.js",['depends' => 'app\assets\AppAsset']) ?>

<?php app\components\JsBlock::begin() ?>
<script type="text/javascript">  
(function($){
    $.fn.hoverDelay = function(options){
        var defaults = {
            hoverDuring: 200,
            outDuring: 200,
            hoverEvent: function(){
                $.noop();
            },
            outEvent: function(){
                $.noop();    
            }
        };
        var sets = $.extend(defaults,options || {});
        var hoverTimer, outTimer;
        return $(this).each(function(){
           $(this).hover(function(){
				clearTimeout(outTimer);
				that = this;
				hoverTimer = setTimeout(function(){sets.hoverEvent.apply(that)}, sets.hoverDuring);
			},function(){
				clearTimeout(hoverTimer);
				that = this;
				outTimer = setTimeout(function(){sets.outEvent.apply(that)}, sets.outDuring);
			});
        });
    }      
})(jQuery);

var Init_id = 0;

$(".deck-onclick").hoverDelay({
    hoverEvent: function(){
    	var id = $(this).data("id");
    	if(id != Init_id){
    		$.get("/cruise/deck/detail-room",{rc_id:id},function(data){
	    		if(data){
	    			var html = '<div class="row">';
						html +=  '<div class="col-md-12"><p class="rc-p">房间号：'+data.room_code+'</p>';
						html +=  '<p class="rc-p">房型：<span class="s1">'+data.type+'</span></p>';
						html +=  '<p class="rc-p">房型代码：'+data.type_code+'</p>';
						html +=  '<p class="rc-p">最大入住：<span class="s3">'+data.num+'</span></p>';
						html +=  '<p class="rc-p">详细床型：<span class="s3">'+data.bed+'</span></p>';
						html +=  '<p class="rc-p">入住人数：<span class="s3">'+data.num2+'</span></p>';
						html +=  '<p class="rc-p">入住姓名：<span class="s3">'+data.username+'</span></p></div>';
			    	    html +='</div>';
			    	$(".room-content").empty();    
			    	$(".room-content").append(html);   
	    		}
    		});
    		Init_id = id;
    	}
        $(".deck-tip").show();
    },
    outEvent:function(){
    	$(".deck-tip").hide();
    }
});


// 清除模态框缓存
$(".code-modal").on("hidden.bs.modal", function() {
	$(this).removeData("bs.modal");
});

//上传团期房间号
$('#file-upload').on('filebatchselected', function(event, files) {
    $(this).fileinput("upload");
});

$('#file-upload').on('fileuploaded', function(event, data, previewId, index) {
    var response = data.response;
    if(response.code == 'error'){
        layer.msg(response.message);
        return false;
    }else if(response.code == 'ok'){
        layer.msg(response.message);
        window.location.reload();
    }
});


var curPage;        //当前页数
var totalItem;      //总记录数
var pageSize;       //每一页记录数
var totalPage;      //总页数

//分页
function getPageBar()
{
  if(curPage > totalPage) {
      curPage = totalPage;
  }
  if(curPage < 1) {
      curPage = 1;
  }
 
  pageBar = "";
 
  //如果不是第一页
  if(curPage != 1){
    	pageBar += "<span class='pageBtn'><a data-page='1' class='pageClick' >首页</a></span>";
    	pageBar += "<span class='pageBtn'><a data-page='"+(curPage-1)+"' class='pageClick'> < </a></span>";
  }
 
  //显示的页码按钮(5个)
  var start,end;
  if(totalPage <= 5) {
    start = 1;
    end = totalPage;
  } else {
    if(curPage-2 <= 0) {
        start = 1;
        end = 5;
    } else {
        if(totalPage-curPage < 2) {
            start = totalPage - 4;
            end = totalPage;
        } else {
            start = curPage - 2;
            end = curPage + 2;
        }
    }
  }
 
  for(var i=start;i<=end;i++) {
    if(i == curPage) {
        pageBar += "<span class='pageBtn-selected'><a data-page='"+i+"' class='pageClick' >"+i+"</a></span>";
    } else {
        pageBar += "<span class='pageBtn'><a data-page='"+i+"' class='pageClick' >"+i+"</a></span>";
    }
  }
   
  //如果不是最后页
  if(curPage != totalPage && curPage != 1){
    	pageBar += "<span class='pageBtn'><a data-page='"+(parseInt(curPage)+1)+"' class='pageClick' > > </a></span>";
    	pageBar += "<span class='pageBtn'><a data-page='"+totalPage+"' class='pageClick' >尾页</a></span>";
  }
     
  $("#Pagination").html(pageBar);
}

$("#Pagination").on("click",".pageClick",function(){
		var page = $(this).data('page');
		ajaxData(page);
});

//ajax加载数据
function ajaxData(page){
	var room_status = '';
	room_status = $("input[name='room-status']:checked").val();
	// var room_tag = new Array();  

	// $("input[name='room-tag']:checked").each(function(){  
	// 	room_tag.push($(this).val());//向数组中添加元素 
	// });
	var room_t = '';  
	room_t = $("#room-t").val(); //房型
	var supply = '';
	supply = $("#supply").val(); //
	var group = '';
	group = $("#group").val();
	var name_t = '';
	name_t = $("#name-t").val();

	$.get("/cruise/deck/get-room",{room_status:room_status,room_t:room_t,supply:supply,group:group,name:name_t,pageNum:page},function(data){
		totalItem = data.totalItem;
      	pageSize = data.pageSize;
      	curPage = page;
      	totalPage = data.totalPage;
      	var data_content = data.data_content;
      
		if(data_content){
			var html = '';
			$.each(data_content,function(r,itroom){
				html += '<div class="order-one row">';
				html += '<div>'
		 		var disabled = '';
		 		if(itroom.code){
	 		 		disabled = 'disabled';
	 		 	} 
		 		html += '<div class="col-md-10">';
		 		html += '<input class="magic-radio deck-magic" type="radio" id="ass_'+itroom.id+'" name="room" data-type="'+itroom.type+'" data-code="'+itroom.type_code+'"  '+disabled+'  data-room='+itroom.id+' data-num='+itroom.num+' data-num2='+itroom.num2+' value='+itroom.id+'>';
		 		html +='<label for="ass_'+itroom.id+'" > '+itroom.name+' |备注: '+itroom.remark+'  | 房间号：<span id="radio_code_'+itroom.id+'">'+(itroom.code?itroom.code:'')+'</span> </label></div>';
		 		 html += '<div class="col-md-2 clear-button" id="clear_code_'+itroom.id+'">';	 
		 		
	 		 	 if(itroom.code){
		 		 	html+= '<a class="clear-code" style="cursor:pointer;" data-id="'+itroom.id+'" data-code="'+itroom.code+'"><i class="fa fa-times-circle" title="清除房号"></i></a>';
		 		 }	 		
		 		html += '</div></div>';
		 		if(itroom.customers){
		 			$.each(itroom.customers,function(i,item){
		 				 html += '<div class="col-md-12">';
		 				 html +=  '<label class="people-one">入住人：'+item.name+' | 团号: '+item.group+' | 体系: '+item.supply+' | 备注: '+item.remark+' </label>';
		 				 html += '</div>';
		 		   });		
		 		}
		 		html += '</div>';		
			});
			
			$(".all-order").empty();
			$(".all-order").append(html);
			$("#loadgif").hide();
			
			getPageBar();
		}else{
			$("#loadgif").hide();
		}
    });
}
//初始化
ajaxData(1);

$("#select-order").click(function(){
	$(".all-order").empty();
	$("#loadgif").show();
	$("#Searchresult").empty();
	$("#Pagination").empty();
	ajaxData(1);
});


//禁止浏览器默认右键点击事件
document.oncontextmenu = function(){  
    return false;  
}  

//右键点击事件
$(".deck").mousedown(function(e) {
	if(3 == e.which){ //右键点击事件
		var url = $(this).attr("data-poload");
		if(url){
			$('#deckModal').modal({
			  remote: url
			})
		}	
	}
});



//清除modal缓存
$(".deck-modal").on("hidden.bs.modal", function() {
	$(this).removeData("bs.modal");
});



//选择房间
$(".all-order").on("click",".deck-magic",function(){	
	var type = $(this).data('type');
	var id = $(this).data('room');
	var num2 = $(this).data('num2');
	var type_code = $(this).data('code');
	$(".tab-pane").each(function(){
		 var i = $(this).data('i');
		 var x = 0;
		 $(this).find(".deck-onclick").each(function(){
		 	var disabled = $(this).data('disabled');
		 	var exit = $(this).data('exit');
		 	if(disabled == 0 && exit == 1){
		 		var tc = $(this).data('type-code');
		 		if(type_code == tc){
		 			x = 1;
		 		}
		 	} 
		 });
		 if(x == 1){
		 	$(".ii_"+i).show();
		 }else{
		 	$(".ii_"+i).hide();
		 }
	});

	$("#select-room").val(id);
	$("#select-room-num").val(num2);	
	
});	

//分配 svg图 房间号
$(".deck-onclick").on("click",function(){

	var _self = $(this);
	var exit = _self.data("exit");
	if(exit == 0){
		alert("未导入");
		return false;
	}
	var disabled = _self.attr("data-disabled");
	if(disabled == 1){
		alert("已分配");
		return false;
	}
	var code = $(this).attr("data-room");

	//var room_id = $("#select-room").val();
	//var room_num = $("#select-room-num").val();//选择房间入住人数
	var checked = $("input[name='room']:checked");
	var room_id = checked.val();
	var room_num = checked.attr("data-num2");
	var num = _self.attr("data-room-num");
	if(room_id == 0 || typeof room_id === "undefined"){
		alert('没有选择房间');
		return false;
	}
	if(num < room_num){
    	var tip_msg = '人数为'+room_num+'人,'+code+' 房间最大入住人为'+num+'人'; 
		if(confirm(tip_msg)){

		}else{
			return false;
		}
    }

	var html = '<a class="clear-code clear-button" style="cursor:pointer;" data-id="'+room_id+'" data-code="'+code+'"><i class="fa fa-times-circle" title="清除房号"></i></a>';

	$.get("/cruise/deck/set-room",{room_id:room_id, code:code},function(data){
		if(data == 1){
			$("#clear_code_"+room_id).append(html);
			alert('分配房号成功!');
			$("#select-room").val(0);
			$("#select-room-num").val(0);
			$("#ass_"+room_id).attr("disabled","disabled");
			$("#ass_"+room_id).prop("checked",false);
			$("#radio_code_"+room_id).text(code);
			var deck_num = _self.data("deck"); //甲板层
			_self.attr("data-disabled",1);
			_self.attr("fill","url(#nt_"+deck_num+")");
			_self.css("cursor","not-allowed");
			$("input[name='room']").prop("checked",false); 
			var num = $(".room_num").text();
			num = parseInt(num) + 1 ;
			$(".room_num").text(num);
		}else{
			alert('分配房号失败!');
			return false;
		}
    });
		
});

//清除房间号
$(".all-order").on("click",".clear-code",function(){
	var _this = $(this);
	var room_id = $(this).data('id');
	var code = $(this).data('code');	
	$.get("/cruise/deck/clear-code",{room_id:room_id},function(data){
		if(data == 1){
			alert('清除房号成功!');
			$("#radio_code_"+room_id).text("");
			$("#ass_"+room_id).removeAttr("disabled");

			var _self = $("path[data-room='"+code+"']");
			var color = _self.data("color");
			_self.attr("data-disabled",0);
			_self.attr("fill",color); 
			_self.css("cursor","pointer");
			_this.remove();
			var num = $(".room_num").text();
			num = parseInt(num) - 1 ;
			$(".room_num").text(num);
		}else{
			alert('清除房号失败!');
			return false;
		}
    });
});


</script>
<?php app\components\JsBlock::end() ?>

  